package ac.manchester.cs.afzal.term_classifier.sql_handler;



import ac.manchester.cs.afzal.term_classifier.sql_handler.SQL_Handler_Impl;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * It contains functions regarding inserting information about stemming in database.
 *
 * @author Hammad Afzal
 * @version 1.0

 */
public class SQL_Handler_Stemming_Impl extends SQL_Handler_Impl
{

    /*
     * It returns the database id of record that corresponds to the given value of noun/verb
     */
    public int get_stem_map_id(String value, int flag)
    {
        int count = 0;
        String query = "";
        try
        {
            statement = connection.createStatement();
            query = (flag == 1)? "SELECT Stem_Map_ID FROM Stem_Map_Ns WHERE Noun = '" + value + "'" :
                                 "SELECT Stem_Map_ID FROM Stem_Map_Vs WHERE Verb = '" + value + "'";

            ResultSet rs = statement.executeQuery(query);

            while(rs.next())
            {
                count = rs.getInt("Stem_Map_ID");
            }
            statement.close();
        }
        catch (SQLException sqlex)
        {
            System.out.println("Value of SQL Exception is : " + sqlex.getMessage());
        }
        return count;
    }
}
